import time

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

rng = pd.date_range("1/1/2012" , periods=100 ,freq='s')
ts = pd.Series(np.random.randint(0,500, len(rng))  , index=rng)
# print(ts.resample("5Min").sum())

df = pd.DataFrame({
    "id":[1,2,3,4,5,6] ,
    "raw_grade":["a","b","a","a","b","c"],
})
df["grade"]=df["raw_grade"].astype("category")
# print(df)
# print(df["grade"])

new_categories = ["very good" , "good" , "very bad"]
# df["grade"] = df["grade"].cat.rename_categories(new_categories)
# print(df["grade"])
df["grade"] = df["grade"].cat.set_categories([
    "very bd" , "bad" , "medium" , "good" , "very good" , "very well"
])
# print(df["grade"])

'''
画图
'''
# plt.close('all') #关闭窗口
datelist = pd.date_range("1/1/2000", periods=1000 )
ts = pd.Series(np.random.randn(1000), index=datelist)
# ts = ts.cumsum()
# plt.figure()
# ts.plot()
# plt.show()
# time.sleep(10)
# plt.close("all")


ts1= pd.DataFrame(
    np.random.randn(1000, 4), index=ts.index , columns=["A","B","C","D"]
)
# ts1 = ts1.cumsum()
# plt.figure()
# ts1.plot()
# plt.legend(loc='best')
# plt.show()

"""
导入和导出数据
"""
exportdf = pd.DataFrame(np.random.randint(0,5,(10,5)))
# exportdf.to_csv("foo.csv")

# exportdf.to_parquet("foo1.parquet")
# print(pd.read_parquet("foo1.parquet"))
# exportdf.to_excel("foo.xlsx" , sheet_name="test")
if pd.Series([False , True , False]):
    print("I was true")